package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.rpframework.core.BaseService;
import com.rpframework.utils.GenerateUtils;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.utils.UUIDGenerator;
import com.rpframework.website.device.dao.IOrderDao;
import com.rpframework.website.device.domain.Order;
import com.rpframework.website.device.util.HConstants;

@Service
public class OrderService extends BaseService {
	public @Resource IOrderDao iDao;
	@Resource GoodsService goodsService;
	
	public Pager<Order> getPager(Pager<Order> pager) {
		long startTime = System.currentTimeMillis();
		List<Order> list = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}
	/**
	 * 修改状态
	 * @param id
	 * @return
	 * @time 2016年3月24日 上午10:02:46
	 */
	public boolean doUpdateState(Integer id) {
		if(NumberUtils.isValid(id)){
			Order t = iDao.select(id);
			if(t.getState() == HConstants.EntityState.STATE_NORMAL){
				t.setState(HConstants.EntityState.STATE_DISABLE);
			}else{
				t.setState(HConstants.EntityState.STATE_NORMAL);
			}
			t.setModifyTime(System.currentTimeMillis()/1000);
			return iDao.update(t);
		}
		return false;
	}
	public String createOrderId() {
		return UUIDGenerator.generate();
	}

	public JsonElement getJsonInfo() {
		JsonObject json = new JsonObject();
		json.addProperty("cnee", "收货人");
		json.addProperty("tel", "电话");
		json.addProperty("address", "收货地址");
		json.addProperty("delivery", "配送时间");
		json.addProperty("goods", "商品信息");
		json.addProperty("name", "商品名字");
		json.addProperty("amount", "商品数量");
		json.addProperty("price", "商品总价");
		json.addProperty("couponSelect", "总价大于物业设置的优惠券使用额度才可以选 0可选  1不可选");
		json.addProperty("priceAmount", "订单商品总额");
		json.addProperty("pointAmount", "可获总积分");
		json.addProperty("coupon", "优惠券");
		json.addProperty("attach", "配送费");
		json.addProperty("attachSet", "满多少钱可以免配送费");
		json.addProperty("attachPrice", "可以免配送费额度");
		return json;
	}

}
